package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.common.query.QueryBuilder;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.NkRsBxlc;
import com.yuncheng.oaApi.service.INkRsBxlcService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 内控-报销流程
 * @Author: lhb
 * @Date: 2023-11-21
 * @Version: V1.0
 */
@Api(tags = "内控-报销流程接口")
@RestController
@RequestMapping("/api/nk/nkRsBxlc")
public class NkRsBxlcController extends BaseController<NkRsBxlc, INkRsBxlcService> {

    private static final Logger log = LoggerFactory.getLogger(NkRsBxlcController.class);

    @Resource
    private INkRsBxlcService nkRsBxlcService;

    /**
     * 分页列表查询
     *
     * @param nkRsBxlc
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "内控-报销流程-分页列表查询")
    @ApiOperation(value = "内控-报销流程-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(NkRsBxlc nkRsBxlc, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        QueryWrapper<NkRsBxlc> queryWrapper = QueryBuilder.initQueryWrapper(nkRsBxlc, req.getParameterMap());
        Page<NkRsBxlc> page = new Page<>(pageNo, pageSize);
        IPage<NkRsBxlc> pageList = nkRsBxlcService.page(page, queryWrapper);
        for(NkRsBxlc vo:pageList.getRecords()){
            formatValue(vo);
        }
        return HttpResult.ok(pageList);
    }


    @AutoLog(value = "内控-报销流程-添加")
    @ApiOperation(value = "内控-报销流程-添加")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody NkRsBxlc nkRsBxlc) {
        HttpResult<String> result = new HttpResult(true);
        nkRsBxlcService.save(nkRsBxlc);
        result.setResult(nkRsBxlc.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }


    @AutoLog(value = "内控-报销流程-编辑")
    @ApiOperation(value = "内控-报销流程-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody NkRsBxlc nkRsBxlc) {
        nkRsBxlcService.updateById(nkRsBxlc);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    @AutoLog(value = "内控-报销流程-通过id删除")
    @ApiOperation(value = "内控-报销流程-通过id删除")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        nkRsBxlcService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    @AutoLog(value = "内控-报销流程-批量删除")
    @ApiOperation(value = "内控-报销流程-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        nkRsBxlcService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    @AutoLog(value = "内控-报销流程-通过id查询")
    @ApiOperation(value = "内控-报销流程-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        NkRsBxlc nkRsBxlc = nkRsBxlcService.getById(id);
        return HttpResult.ok(nkRsBxlc);
    }

    /**
     * 数据转换
     * @param nkRsBxlc
     */
    private void formatValue(NkRsBxlc nkRsBxlc){
    }
}
